package com.ktgj.flight.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ktgj.flight.domain.FlightOrderIternaryDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.flight.domain.FlightDeliverAssign;
import com.ktgj.flight.service.IFlightDeliverAssignService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 机票行程单配送Controller
 * 
 * @author ruoyi
 * @date 2022-06-28
 */
@RestController
@RequestMapping("/assign")
public class FlightDeliverAssignController extends BaseController
{
    @Autowired
    private IFlightDeliverAssignService flightDeliverAssignService;

    /**
     * 查询机票行程单配送列表
     */
    @PreAuthorize(hasPermi = "flight:assign:list")
    @GetMapping("/list")
    public TableDataInfo list(FlightDeliverAssign flightDeliverAssign)
    {
        startPage();
        List<FlightDeliverAssign> list = flightDeliverAssignService.selectFlightDeliverAssignList(flightDeliverAssign);
        return getDataTable(list);
    }

    /**
     * 导出机票行程单配送列表
     */
    @PreAuthorize(hasPermi = "flight:assign:export")
    @Log(title = "机票行程单配送", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FlightDeliverAssign flightDeliverAssign) throws IOException
    {
        List<FlightDeliverAssign> list = flightDeliverAssignService.selectFlightDeliverAssignList(flightDeliverAssign);
        ExcelUtil<FlightDeliverAssign> util = new ExcelUtil<FlightDeliverAssign>(FlightDeliverAssign.class);
        util.exportExcel(response, list, "机票行程单配送数据");
    }

    /**
     * 获取机票行程单配送详细信息
     */
    @PreAuthorize(hasPermi = "flight:assign:query")
    @GetMapping(value = "/{assignId}")
    public AjaxResult getInfo(@PathVariable("assignId") Long assignId)
    {
        return AjaxResult.success(flightDeliverAssignService.selectFlightDeliverAssignById(assignId));
    }

    /**
     * 新增机票行程单配送
     */
    @PreAuthorize(hasPermi = "flight:assign:add")
    @Log(title = "机票行程单配送", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FlightDeliverAssign flightDeliverAssign)
    {
        return toAjax(flightDeliverAssignService.insertFlightDeliverAssign(flightDeliverAssign));
    }

    /**
     * 修改机票行程单配送
     */
    @PreAuthorize(hasPermi = "flight:assign:edit")
    @Log(title = "机票行程单配送", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FlightDeliverAssign flightDeliverAssign)
    {
        return toAjax(flightDeliverAssignService.updateFlightDeliverAssign(flightDeliverAssign));
    }

    /**
     * 删除机票行程单配送
     */
    @PreAuthorize(hasPermi = "flight:assign:remove")
    @Log(title = "机票行程单配送", businessType = BusinessType.DELETE)
	@DeleteMapping("/{assignIds}")
    public AjaxResult remove(@PathVariable Long[] assignIds)
    {
        return toAjax(flightDeliverAssignService.deleteFlightDeliverAssignByIds(assignIds));
    }

    /**
     * 回填快递单号
     * @param iternaryDTO
     * @return
     */
    @PostMapping("/updateDeliverAssignByOrderId")
    public AjaxResult updateDeliverAssignByOrderId(@RequestBody FlightOrderIternaryDTO iternaryDTO) {
        return toAjax(flightDeliverAssignService.updateDeliverAssignByOrderId(iternaryDTO));
    }
}
